package com.yumingjaing.thread;

/**
 * @description:
 * @author: John
 * @version: TestThreadLocal.java, v1.0 2024年12月15日 08:49
 */
public class TestThreadLocal {
    static ThreadLocal<String> tl1 = new ThreadLocal<>();
    static ThreadLocal<String> tl2 = new ThreadLocal<>();

    public static void main(String[] args) {
        tl1.set("123");
        tl2.set("456");
        Thread t1 = new Thread(() -> {
            System.out.println("t1:" + tl1.get());
            System.out.println("t1:" + tl2.get());
        });
        t1.start();

        System.out.println("main:" + tl1.get());
        System.out.println("main:" + tl2.get());
        //使用完及时remove防止内存泄漏
        tl1.remove();
        tl2.remove();
    }
}